package com.lfs.market.controller.admin;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.annotation.SaMode;
import com.lfs.market.model.R;
import com.lfs.market.model.vo.StatCategoryVo;
import com.lfs.market.model.vo.StatMonthlyDealVo;
import com.lfs.market.model.vo.StatSaleVo;
import com.lfs.market.model.vo.StatWeeklyDealVo;
import com.lfs.market.service.OrdersService;
import com.lfs.market.service.ProductInfoService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/admin/stat")
@SaCheckRole(value = {"admin", "system", "check"}, mode = SaMode.OR)
@SaCheckLogin
public class StatController {
    @Resource
    private OrdersService ordersService;

    @Resource
    private ProductInfoService productInfoService;

    /**
     * 查询每日订单
     *
     * @return
     */
    @GetMapping("/daily/order")
    public R getDailyOrder() {
        Integer dailyOrders = ordersService.getDailyOrder();
        return R.ok(dailyOrders);
    }

    /**
     * 查询本日销售额
     *
     * @return
     */
    @GetMapping("/daily/sale")
    public R getSalesToday() {
        BigDecimal dailyOrders = ordersService.getSalesToday();
        return R.ok(dailyOrders);
    }

    /**
     * 查询本日新增
     *
     * @return
     */
    @GetMapping("/daily/new")
    public R getTodayNewProductsCount() {
        Integer dailyOrders = productInfoService.getTodayNewProductsCount();
        return R.ok(dailyOrders);
    }

    /**
     * 查询本月订单数量
     *
     * @return
     */
    @GetMapping("/month/order")
    public R getMonthOrder() {
        Integer dailyOrders = ordersService.getMonthOrder();
        return R.ok(dailyOrders);
    }

    /**
     * 查询本月销售额
     *
     * @return
     */
    @GetMapping("/month/sale")
    public R getSalesMonth() {
        BigDecimal dailyOrders = ordersService.getSalesMonth();
        return R.ok(dailyOrders);
    }

    /**
     * 查询本月新增
     *
     * @return
     */
    @GetMapping("/month/new")
    public R getMonthNewProductsCount() {
        Integer dailyOrders = productInfoService.getMonthNewProductsCount();
        return R.ok(dailyOrders);
    }

    /**
     * 查询统计商品数据
     *
     * @return
     */
    @GetMapping("/countData")
    public R<Map> getCountData() {
        Map map = productInfoService.getCountData();
        return R.ok(map);
    }


    /**
     * 分类饼图
     *
     * @return
     */
    @GetMapping("/category")
    public R getCategoryData() {
        List<StatCategoryVo> categoryData = ordersService.getCategoryData();
        return R.ok(categoryData);
    }


    /**
     * 各月份交易柱状图
     *
     * @return
     */
    @GetMapping("/monthlyDeal")
    public R getMonthlyDeal() {
        List<StatMonthlyDealVo> statMonthlyDealVos = ordersService.getMonthlyDeal();
        return R.ok(statMonthlyDealVos);
    }

    /**
     * 本周交易折线图
     *
     * @return
     */
    @GetMapping("/weeklyDeal")
    public R getWeeklyDeal() {
        List<StatWeeklyDealVo> weeklyDeal = ordersService.getWeeklyDeal();
        return R.ok(weeklyDeal);
    }

    @GetMapping("/saleData")
    public R getSaleData() {
        List<StatSaleVo> saleData = ordersService.getSaleData();
        return R.ok(saleData);
    }
}
